package com.group525.cloudef.controller.admin;

import com.group525.cloudef.common.CommonResult;
import com.group525.cloudef.entity.admin.User;
import com.group525.cloudef.entity.doctor.DUser;
import com.group525.cloudef.service.admin.userService;
import com.group525.cloudef.service.doctor.DUserService;
import com.group525.cloudef.utils.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@RequestMapping("/admin/doctor")
@CrossOrigin
@Api(tags = "医生管理")
public class doctorController {
    //TODO 获取所有医生 编辑医生  删除医生
    @Resource
    DUserService dUserService;
    @Resource
    Log log;
    @GetMapping("/getDoctors/{area}/{buwei}")
    @ApiOperation(value = "筛选医生")
    public List<DUser> getDoctors(@PathVariable String area, @PathVariable String buwei){
        log.debug("地区：",area );
        log.debug("部位：",buwei);
        return dUserService.getDoctors(area,buwei);
    }

    @PostMapping("/editDoctor")
    @ApiOperation(value = "编辑医生")
    public CommonResult<?> editDoctor(@RequestBody DUser dUser){
        log.debug("编辑的医生信息：",dUser);
        if (dUserService.updateById(dUser)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @DeleteMapping("/deleteDoctorById/{id}")
    public CommonResult<?> deleteDoctorById(@PathVariable String id){
        if(dUserService.removeById(id)){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

}
